﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Invoicing.Model.Products;
namespace Invoicing.Command.Products
{
    public class ProductSizeCommand
    {
        public static ProductSizeCollection Gets(ProductSizeQuery sea)
        {
            var ret = new ProductSizeCollection();
            using (DBCentre db = new DBCentre())
            {
                IQueryable<ProductSize> q = db.DataContext.ProductSizes;
                if (sea != null)
                {
                    if (sea.PType > 0)
                        q = q.Where(p => p.PType == sea.PType);
                }
                var n = q.Count();
                if (n > 0)
                {
                    q = q.OrderBy(p => p.ID);
                    var lst = q.ToList();
                    ret = Convertor.ConvertCollection<ProductSizeModel, ProductSize, ProductSizeCollection>(lst);
                    ret.TotalRecordsCount = n;
                }
            }
            return ret;
        }
    }
}
